package com.swq.java.code.chapter10.code09;

import java.lang.reflect.Field;
import java.net.URLClassLoader;
import java.net.URL;

public class Tester {
    public static void main(String[] args) throws Exception {
        URL url = new URL("http://www.javathinker.net/book/classes/");
        URLClassLoader loader = new URLClassLoader(new URL[]{url}); //父加载器为系统类加载器
        Class objClass = loader.loadClass("Sample");
        Object obj = objClass.newInstance();
        System.out.println(obj.toString());
        Field f = objClass.getField("v1");  //运用Java反射机制
        int v1 = f.getInt(obj);
        System.out.println("v1=" + v1);
    }
}